package com.tang.excel.pa.mapper;

import com.tang.excel.pa.domain.EmQuestionCase;
import org.apache.ibatis.jdbc.SQL;

import java.util.Objects;

/**
 * @author Tang
 * @classname EmQuestionCaseSqlProvider
 * @description [  ]
 * @date 2021/4/21 21:23
 */
public class EmQuestionCaseSqlProvider {

    public String sqlByCondition(EmQuestionCase emQuestionCase) {
        SQL sql = new SQL() {
            {
                SELECT("*");
                FROM("em_question_case");
                Integer id = emQuestionCase.getId();
                if (Objects.nonNull(id)) {
                    WHERE("id = " + id);
                }
                Integer caseId = emQuestionCase.getCaseId();
                if (Objects.nonNull(caseId)) {
                    WHERE("case_id = " + caseId);
                }
                Integer topicId = emQuestionCase.getTopicId();
                if (Objects.nonNull(topicId)) {
                    WHERE("topic_id = " + topicId);
                }
            }
        };
        return sql.toString();
    }

}